﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EditCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label10.Visible = false;
            
            LoadData();
        }
      
      
    
      
    }

    private void LoadData()
    {
        ManagementUser ms = new ManagementUser();
        string id = Request.QueryString["id"].ToString();
        ORANGE_PROJECTModel.Manager m = (ORANGE_PROJECTModel.Manager)ms.GetEditUser(id);
        txtID.Text = (id).ToString();
        txtName.Text = m.Name;
        txtPhone.Text = m.Phone;
        txtEmail.Text = m.Email;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"].ToString();
        ManagementUser ms = new ManagementUser();
        ORANGE_PROJECTModel.Manager m = (ORANGE_PROJECTModel.Manager)ms.GetEditUser(id);
        string password=m.Password;
        if(txtPass0.Text!="")
        {
            password = txtPass0.Text;
        }
        if (ms.UpdateUser(txtID.Text, txtName.Text, txtPhone.Text, txtEmail.Text, password))
        {
            Session["fullname"] = txtName.Text;
            Label10.Visible = true;
            Label10.Text = "<span style='color:green;font-weight: bold;'>Update Succerfully :)</span>";

        }
        else
        {
            Label10.Visible = true;
            Label10.Text = "<span style='color:red;font-weight: bold;'>Update Failed (:</span>";
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"].ToString();
        ManagementUser ms = new ManagementUser();
        if (ms.DeleteUser(id))
        {
            Response.Redirect("User.aspx");
        }
    }
}